<?php
	/**
	* @package ParkFind
	* @desc This is the proposal page. This is where users can make proposal for new park or equipment.
	*/
	/**
	* @desc This include file will load the directory settings for the Smarty Templates
	*/
	session_start();
	
	// Direct calling check
	if(!isset($_SESSION["user_id"]))
		die("Forbidden Access");
		
	
	//Smarty
	require 'includes/smarty.inc';
	$smarty->assign('title', "Proposal");
	$smarty->assign('user_id', $_SESSION["user_id"]);	
	$smarty->assign('last', $_SESSION["lastviewed"]);
	$smarty->assign('firstname', $_SESSION["firstname"]);
	$smarty->assign('role', $_SESSION["role"]);
	$smarty->assign('top5', $_SESSION["top5"]);	
	$smarty->display('header.tpl');
	
	
	/**
	* @desc This include file will load the functions that are required to call 
	*		from the database
	*/
	require 'includes/db_functions.inc';
	/**
	* @desc This include file connects to the database.
	*/
	require 'includes/connect.inc';
	
	// Types *************************************
	$types = getParkTypes(); // Get the park types
	$arTypes = array();
	
	if ($types == FALSE)
		$arTypes[] = 'Failed to load';
	else						
		//Iterate through results, extracting park types		
		while($row = mysql_fetch_array($types))
			$arTypes[] = $row["type"];
	
	$smarty->assign('types', $arTypes);
	
	if (isset($_SESSION["errors"]["type"]))
		$smarty->assign('typeerr', $_SESSION["errors"]["type"]);	
	
	// Address	*************************************
	if (isset($_SESSION["form"]["address"]))
		$smarty->assign('address', $_SESSION["form"]["address"]);

	if (isset($_SESSION["errors"]["address"]))
		$smarty->assign('addresserr', $_SESSION["errors"]["address"]);			
		
					
	// Suburbs **********************************
	$suburbs = getSuburbs(); // Get suburbs info
	$arSuburbs = array();
	
	if ($suburbs == FALSE)
		$arSuburbs = array('postcode' => 'error', 'name' => 'Failed to Load');
	else						
		//Iterate through results, extracting suburb name and postcode		
		while($row = mysql_fetch_array($suburbs))
			$arSuburbs[] = array('id' => $row["suburb_id"], 'name' => $row["name"], 'postcode' => $row["postcode"]);
		 
	$smarty->assign('suburbs', $arSuburbs);
	
	if (isset($_SESSION["errors"]["suburb"]))
		$smarty->assign('suburberr', $_SESSION["errors"]["suburb"]);	

	// Suggested Name	*************************************
	if (isset($_SESSION["form"]["sugname"]))
		$smarty->assign('sugname', $_SESSION["form"]["sugname"]);

	if (isset($_SESSION["errors"]["sugname"]))
		$smarty->assign('sugnameerr', $_SESSION["errors"]["sugname"]);	
			
	// Details	*************************************
	if (isset($_SESSION["form"]["details"]))
		$smarty->assign('details', $_SESSION["form"]["details"]);

	if (isset($_SESSION["errors"]["details"]))
		$smarty->assign('detailserr', $_SESSION["errors"]["details"]);						
			
	$smarty->display('proposal.tpl');
	
	unset($_SESSION["errors"]);
	unset($_SESSION["form"]);
	$smarty->display('footer.tpl');
	
?>
